<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
  <head>
    <base href="<%=basePath%>">
	<%@ include file="/base/jsp/include.jsp"%>
  </head>
  <body>
    <form id="form" method="post">
        <input name="id" class="mini-hidden" />
        <fieldset style="border:solid 1px #aaa;padding:10px;">
            <legend >添加</legend>
            <div style="padding:5px;">
            <table class="editor_table">
            	 <tr>
                    <td style="width:70px;">科目：</td>
                    <td style="width:150px;">
                    <input name="subId" id="subId" value="" required="true" class="mini-combobox" textField="text" valueField="id" emptyText="科目"
                        url="${path}/base/subjectForNote.json" allowInput="false" showNullItem="true" nullItemText="请选择..."/>
                    </td>
                </tr>
                
                <tr>
                    <td style="width:200px;">名称：</td>
                    <td style="width:150px;">
                    	<input name="name" id="name" class="mini-textbox editor_len" required="true" vtype="maxLength:150" emptyText="请输入名称"/>
                    </td>
                </tr>
            </table>            
         </div>
        </fieldset>
        
        <div style="text-align:center;padding:10px;">  
            <a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>       
            <a class="mini-button" onclick="onCancel" style="width:60px;margin-right:20px">取消</a>
        </div>        
    </form>
    
    <script type="text/javascript">
    	var id = '';
        mini.parse();
        var form = new mini.Form("form");
        function SaveData() {
			var o = form.getData(true);
            form.validate();
            if (form.isValid() == false) return;
            var json = mini.encode(o);
            mini.alert(json);
            $.ajax({
                url: "saveSubject.do",
                type: 'post',
                data: $.evalJSON(json),
                cache: false,
                success: function (text) {
                	if(text.indexOf('true') > -1){
				    	mini.alert("操作成功");
				    	CloseWindow("save");
				    }else if(text.indexOf('false') > -1){
				    	mini.alert("操作失败");
				    	CloseWindow();
				    }else if(text.indexOf('date') > -1){
				    	mini.alert("该日期已有了推荐图片");
				    	//CloseWindow();
				    }
                },
                error: function (textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                    CloseWindow();
                }
            });
        }
        
        //标准方法接口定义
        function SetData(data) {
            if (data.action == "edit") {
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);
                $.ajax({
                    url: "findByIdSubject.do?id=" + data.id,
                    cache: false,
                    success: function (text) {
                        var o = mini.decode(text);
                        form.setData(o);
                        form.setChanged(false);
                        id = o.id;
                       
                    }
                });
            }
        }

        function GetData() {
            var o = form.getData();
            return o;
        }
        
        function CloseWindow(action) {
            if (action == "cancel" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                	SaveData();
                	return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();            
        }
        function onOk(e) {
        	/*var imgId = mini.get("img").getValue();
        	if(imgId == ""){
        		mini.alert("请上传图片");
        		return ;
        	}
        	*/
            SaveData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
        function onClearFile(e){
            $("#file_upload").clearFileId();
        	mini.get("img").setValue("");
        }
        function onClearFileGn2(e){
            $("#file_upload_gn2").clearFileId();
        	mini.get("imgGn2").setValue("");
        }
         function onClearFileGn3(e){
            $("#file_upload_gn3").clearFileId();
        	mini.get("imgGn3").setValue("");
        }
         function onClearFileZj(e){
            $("#file_upload_zj").clearFileId();
        	mini.get("imgZj").setValue("");
        }
        function onUploadSuccess(e) {
              mini.get("img").setValue($("#file_upload").getFileId());
        }
        function onUploadSuccessGn2(e) {
              mini.get("imgGn2").setValue($("#file_upload_gn2").getFileId());
        }
        function onUploadSuccessGn3(e) {
              mini.get("imgGn3").setValue($("#file_upload_gn3").getFileId());
        }
        function onUploadSuccessZj(e) {
              mini.get("imgZj").setValue($("#file_upload_zj").getFileId());
        }
    </script>
  </body>
</html>
